import esbuild from 'esbuild';

async function buildExtension() {
  try {
    await esbuild.build({
      entryPoints: ['src/extension.ts'],
      bundle: true,
      outfile: 'dist/extension.js',
      format: 'esm',
      platform: 'node',
      target: 'node16',
      external: [
        'vscode',
        'miniprogram-ci',
        'fs',
        'path',
        'crypto',
        'os',
        'child_process',
        'stream',
        'zlib',
        'http',
        'https',
        'url',
        'util',
        'assert',
        'constants',
        'readline',
        'debug'
      ],
      sourcemap: true,
      minify: false,
      define: {
        'process.env.NODE_ENV': '"production"',
      },
      loader: {
        '.ts': 'ts',
        '.js': 'js',
      },
      tsconfig: './tsconfig.json',
      logLevel: 'warning',
    });
    
    console.log('✅ Extension built successfully!');
  } catch (error) {
    console.error('❌ Build failed:', error);
    process.exit(1);
  }
}

buildExtension();